<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>命名路由</title>

    <script src="./../vue/vue.js"></script>
    <script src="./../vue/vue-router.js"></script>
</head>
<body>

    <div id="app">
        <div>
            <ul>
                <li>
                    <a href="#" @click.prevent="onClickPush">进入</a>
                </li>
            </ul>
        </div>
        <router-view></router-view>
    </div>

    <script>

        const Route = {
            computed: {
                nickName(){
                    return this.$route.params.name
                }
            },
            template: `
            <div>
                Route
                <div>{{nickName}}</div>
            </div>
            `
        }

        const router = new VueRouter({
            routes: [
                {
                    name: 'route',
                    path: '/route/:name',
                    component: Route
                }
            ]
        })
        let vm = new Vue({
            router,
            el: "#app",
            data: {

            },
            methods: {
                onClickPush(){
                    router.push({name: 'route',params: {name: '小明'}})
                }
            },
        })

    </script>
    
</body>
</html>